package cn.hp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.hp.domain.Permission;
import cn.hp.service.PermissionService;

@Controller
@RequestMapping("/permission")
@Secured({"ROLE_ADMIN"})
public class PermissionController {
	
	@Autowired
	private PermissionService permissionService;
	
	
	
	//查询所有权限
	@RequestMapping("/findAll")
	public ModelAndView findAll(){
		List<Permission> permissionList=permissionService.findAll();
		ModelAndView andView=new ModelAndView();
		andView.addObject("permissionList", permissionList);
		andView.setViewName("permission-list");
		return andView;
		
	}
	
	
	//回显父权限
	@RequestMapping("/addUI")
	public ModelAndView addUI(){
		List<Permission> permissionList=permissionService.addUI();
		ModelAndView andView=new ModelAndView();
		andView.addObject("permissionList", permissionList);
		andView.setViewName("permission-add");
		return andView;
	}
	
	//添加权限
	@RequestMapping("/save")
	public String save(Permission permission){
		permissionService.save(permission);
		return "redirect:findAll";
	}
	
}
